import { Directive, TemplateRef, ViewContainerRef } from '@angular/core';

@Directive({
    selector: '[opProjectedTemplate]'
})
export class ProjectedTemplateDirective {
    constructor(
        private templateRef: TemplateRef<any>,
        private viewContainerRef: ViewContainerRef
    ) {
        // createEmbeddedView binds the template with the context, $implicit default value is an empty object.
        // The $implicit value will be updated by ngTemplateOutletContext from the ng-template later on.
        // Check $implicit examples on 
        // https://stackoverflow.com/questions/45055384/what-is-implicit-in-angular-2/45055768#45055768
        // https://stackoverflow.com/questions/47944677/wrap-angular-ngfor-directive-with-another-structural-directive
        this.viewContainerRef.createEmbeddedView(this.templateRef, { $implicit: {} });
    }
}